//
//  WKVoiceCellFrame.m
//  WKDemo
//
//  Created by apple on 14-8-6.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKVoiceCellFrame.h"
#import "WKVoiceModel.h"

@implementation WKVoiceCellFrame

-(void)setModel:(WKVoiceModel *)model{
    _model=model;
    
    CGFloat margin=10;
    _iconFrame=CGRectMake(margin, margin, 35, 35);
    
    CGFloat nameX=CGRectGetMaxX(_iconFrame)+margin;
    CGFloat nameY=margin;
    CGSize nameSize=[model.name boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
    _nameFrame=(CGRect){{nameX,nameY},nameSize};
    
    CGFloat timeX=nameX;
    CGFloat timeY=CGRectGetMaxY(_nameFrame)+margin*0.5;
    CGSize timeSize=[model.passtime boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil].size;
    _timeFrame=(CGRect){{timeX,timeY},timeSize};
    
    CGFloat contentY=CGRectGetMaxY(_iconFrame)+margin;
    CGFloat contentX=margin;
    CGSize contentSize=[model.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-2*margin, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
    _contentFrame=(CGRect){{contentX,contentY},contentSize};
    
    CGFloat contentImgX = margin;
    CGFloat contentImgY = CGRectGetMaxY(_contentFrame)+margin;
    CGFloat contentImgW = 300;
    CGFloat contentImgH = 280;
    _contentImgFrame=CGRectMake(contentImgX, contentImgY, contentImgW, contentImgH);
    
    
    //计算播放按钮的frame
    CGFloat playBtnX=_contentImgFrame.size.width*0.5-20;
    CGFloat playBtnY=_contentImgFrame.size.height-30;
    _playButtonFrame=CGRectMake(playBtnX, playBtnY, 40, 40);
    
    //显示播放时长label的frame
    int voicetime = model.voicetime.intValue;
    NSString *time = nil;
    if (voicetime >60) {
        time = [NSString stringWithFormat:@"%0d:%02d",voicetime/60,voicetime%60];
    }else
    {
        time = [NSString stringWithFormat:@"00:%02d",voicetime];
    }
    CGSize voiceLengthSize = [time boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{UITextAttributeFont:[UIFont systemFontOfSize:10]} context:nil].size;
    CGFloat voiceLengthW= voiceLengthSize.width;
    CGFloat voiceLengthH= voiceLengthSize.height;
    CGFloat voiceLengthX=_contentImgFrame.size.width-voiceLengthW;
    CGFloat voiceLengthY=self.contentImgFrame.size.height - voiceLengthH;
    _voiceLengthFrame=CGRectMake(voiceLengthX, voiceLengthY, voiceLengthW, voiceLengthH);
    
    
    //显示播放次数label的frame
    NSString *count = [NSString stringWithFormat:@"%@次播放",model.playcount];
    
    CGSize playCountSize = [count boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{UITextAttributeFont:[UIFont systemFontOfSize:10]} context:nil].size;
    CGFloat playCountW = playCountSize.width;
    CGFloat playCountH = playCountSize.height;
    CGFloat playCountX = contentImgW - playCountW;
    CGFloat playCountY = 0;
    _playCountFrame=CGRectMake(playCountX, playCountY, playCountW, playCountH);
    
    CGFloat toolbarX=contentImgX;
    CGFloat toolbarY=CGRectGetMaxY(_contentImgFrame)+margin;
    _toolbarFrame=CGRectMake(toolbarX, toolbarY, [UIScreen mainScreen].bounds.size.width-margin*2, 44);
    
    
    //_cellHeight=CGRectGetMaxY(_contentImgFrame);
    _cellHeight=CGRectGetMaxY(_toolbarFrame);
}
@end
